package training;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_9_3_Training {
    //人员站位的方案数 II
    public int numberOfPairs(int[][] points) {
        Arrays.sort(points,(x, y)->{
            if(x[0]==y[0]) return x[1]-y[1];
            return y[0]-x[0];
        });
        int len = points.length;
        int ans=0;
        List<int[]> list;
        for(int i=0;i<len;++i){
            list = new ArrayList<>();
            for(int j=i+1;j<len;++j){
                //右上角确定
                if(points[i][0]>=points[j][0] && points[i][1]<=points[j][1] && containsXy(list,points[j][0],points[j][1]) ){
                    ans++;
                    list.add(points[j]);
                }
            }
        }
        return ans;
    }

    public boolean containsXy(List<int[]> list , int x, int y){
        if(list.size()<1) return true;
        for(int[] a1 : list){
            if(a1[0]>=x && a1[1]<=y){
                return false;
            }
        }
        return true;
    }
}
